
class Link
  attr_accessor :link, :caption, :rm, :ram, :mp3
  def initialize(link)
    @link = link
    get_rm
    get_ram
  end
  
  def get(regex)
    @link.href.scan(regex)[0] if link.href
  end
  
  def get_rm
    @rm = get(/http:.+.rm/)
  end
  
  def get_ram
    @ram = get(/http:.+.ram/)
  end
  
  def mp3
    ".\\mp3\\#{get_caption}.mp3"
  end
  
  def get_caption
  #.gsub('.', '_')
    @caption = @link.href[@link.href.rindex(/\/.+.rm|\/.+.ram/)+1, @link.href.length].gsub('.rm', '').gsub('.ram', '') unless @caption
    return @caption
  end
  
  def valid?
    (!@rm.nil? and @rm.length>0) or (!@ram.nil? and @ram.length>0)
  end
  
  def valid_rm?
    !@rm.nil? and @rm.length>0
  end
  
  def valid_ram?
    !@ram.nil? and @ram.length>0
  end
end
